﻿Public Class Domba
    Dim vHunger As Integer
    Dim vThirst As Integer
    Dim vCond As String
    Dim vGauge As Integer = 100
    Friend vExp As Integer
    Friend vStat As Integer

    'Start-up
    Private Sub Domba_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Grow()
    End Sub


    'Interaction
    Friend Sub Grow()
        Dim x, y As Integer

        'Check Exp

        If vExp >= 100 Then
            If vStat < 3 Then
                vExp = vExp - 100
                vStat += 1
            ElseIf vStat = 3 Then
                vExp = 100
                Form1.Done()
                MessageBox.Show("Your Score : " & Form1.Pts.Text, "Result")
                Me.ParentForm.Close()
            End If
        End If
        ProgressBar3.Value = vExp

        'Check Grow Status
        Select Case vStat
            Case 0
                Label2.Text = "Baby"
                x = 80
                y = 80
            Case 1
                Label2.Text = "Junior"
                x = 110
                y = 110
            Case 2
                Label2.Text = "Senior"
                x = 140
                y = 140
            Case 3
                Label2.Text = "Adult"
                x = 170
                y = 170
        End Select
        PictureBox1.Width = x
        PictureBox1.Height = y
    End Sub

    Friend Sub Eat()
        For Each i As Control In Me.ParentForm.Controls
            If i.Name = "Grass" Then
                Dim x As Integer = 20
                If ProgressBar1.Value > x And i.Text > x Then
                    ProgressBar1.Value -= x
                    i.Text -= x
                    vExp += 12
                    Grow()
                Else
                    If ProgressBar1.Value <= x And i.Text > x Then
                        MsgBox("No Eating Yet")
                    ElseIf ProgressBar1.Value > x And i.Text <= x Then
                        MsgBox("Please replant the grass")
                    ElseIf ProgressBar1.Value <= x And i.Text <= x Then
                        MsgBox("Not Yet")
                    End If
                End If
            End If
        Next
    End Sub

    Friend Sub Drink()
        For Each j As Control In Me.ParentForm.Controls
            If j.Name = "Water" Then
                Dim x As Integer = 25
                If ProgressBar2.Value > x And j.Text > x Then
                    ProgressBar2.Value -= x
                    j.Text -= x
                    vExp += 8
                    Grow()
                Else
                    If ProgressBar2.Value <= x And j.Text > x Then
                        MsgBox("No Drinking Yet")
                    ElseIf ProgressBar2.Value > x And j.Text <= x Then
                        MsgBox("Please refill the water")
                    ElseIf ProgressBar2.Value <= x And j.Text <= x Then
                        MsgBox("Not Yet")
                    End If
                End If
            End If
        Next
    End Sub

    Friend Sub Shave()
        Dim z As New Wool
        z.vCnd = vCond
        If vStat > 0 Then
            Me.Controls.Add(z)
            z.Left = Label9.Left
            z.Top = Label9.Bottom + 20
        End If
    End Sub


    Private Sub Cut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cut.Click
        If vGauge = 100 Then
            Shave()
            vGauge = 0
            Timer4.Enabled = True
        Else
            MsgBox("Wool is not ready to be shaved yet")
        End If
    End Sub

    Private Sub Adjust()
        ProgressBar1.Top = PictureBox1.Bottom + 20
        ProgressBar2.Top = ProgressBar1.Top + 30
    End Sub


    'Elemen
    'Handle Hunger & Thirst Level
    Friend Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If ProgressBar1.Value < 100 Then
            ProgressBar1.Value += 5
            vHunger = ProgressBar1.Value
        End If
    End Sub

    Friend Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If ProgressBar2.Value < 100 Then
            ProgressBar2.Value += 10
            vThirst = ProgressBar2.Value
        End If
    End Sub

    'Handle Condition Status
    Friend Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If ProgressBar1.Value <= 50 And ProgressBar2.Value <= 50 Then
            vCond = "Normal"
        ElseIf (ProgressBar1.Value < 100 And ProgressBar2.Value <= 50) Or (ProgressBar1.Value <= 50 And ProgressBar2.Value < 100) Or (ProgressBar1.Value < 100 And ProgressBar2.Value < 100) Then
            vCond = "Weak"
        Else
            vCond = "Sick"
        End If
        Label3.Text = vCond
        If vCond = "Sick" Or vStat = 0 Then
            Cut.Enabled = False
        Else
            Cut.Enabled = True
        End If
    End Sub

    'Handle Shave gauge
    Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
        If vGauge < 100 Then
            vGauge += 5
            ProgressBar4.Value = vGauge
        Else
            Timer4.Enabled = False
        End If
    End Sub

    'Inisialisasi

    Public Sub Mulai()
        Timer1.Enabled = True
        Timer2.Enabled = True
        Timer3.Enabled = True
    End Sub


End Class
